<%@page import="com.easy.base.service.impl.ESession"%>
<%@page import="com.easy.system.domain.Lov"%>
<%@page import="com.easy.common.util.Parameter"%>
<%@page import="com.easy.auth.domain.Reportlog"%>
<%@page import="com.easy.common.util.DateUtil"%>
<%@page import="java.io.File"%>
<%@ page import=" com.easy.auth.domain.FileComparator" %>
<%@ page import=" com.easy.auth.domain.Impreport" %>
<%@ page import=" com.easy.auth.domain.Report" %>
<%@ page import=" com.easy.auth.domain.Reportlog" %>
<%@ page import=" com.easy.auth.domain.UploadFile" %>
<%@page import="com.easy.base.service.impl.ESession"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>匹配数据处理平台</title>
<%
	ESession eSession = ESession.create(session);
	String sid = request.getParameter("secondMenuId");
	List<Impreport> impreportList = (List<Impreport>)request.getAttribute("impreportList");
	List<Report> newReports = (List<Report>)request.getAttribute("newReports");
	request.getSession().setAttribute("secondMenuId", sid);
	List<Reportlog> reportlogList = (List<Reportlog>)request.getAttribute("reportlogList");
	List<UploadFile> uploadFileList = (List<UploadFile>)request.getAttribute("uploadFileList");
	//String urlheader=request.getContentType().replace("8080","8888").replace("easy","img/").replace("devfw","img/");
%>
<%@include file="/jsp/include/common.jsp"%>
<style>
   
</style>

</head>
 
<body class="easyui-layout">
 <%@include file="/jsp/include/commonLayout.jsp"%> 
<%-- <%@include file="/jsp/include/dpvTop.jsp"%> --%>

	<div data-options="region:'center',fit:true,border:false">
		
		<div id="cc1" class="easyui-layout"	style="width: 100%; height: 700px;/* MARGIN-RIGHT: auto; MARGIN-LEFT: auto; */" >
					<div data-options="region:'west',split:true,title:'零件树',collapsed:false," style="width:250px;height: 550px;padding:10px;">
						  <div>
							<span style="letter-spacing: 1em">工</span>厂<span style="letter-spacing: 0.1em">：</span> 
							<input id="gongchang"  name="gongchang" value="" style="width: 121px;"> 
							</div>
							  <div style="margin-top: 5px">
							<span style="letter-spacing: 1em">车</span>型<span style="letter-spacing: 0.1em">：</span> 
							<input id="chexing" class="combobox" name="chexing" value="" style="width: 121px;">  
						</div>
							 <div style="margin-top: 5px">
						零件号<span style="letter-spacing: 0.1em">：</span> 
						<input id="partTreeSearch"   class="easyui-searchbox"  style="width: 121px">
					 </div>
							<ul id="partTree" class="easyui-tree"></ul>
							<div style="padding-bottom: 30px"></div>
					</div>
				
			<div data-options="region:'center',border:false" >
			<div id="first"  data-options="iconCls:'icon-reload'" style="width:100%;">
				<div title="一工厂" class="easyui-panel"  data-options="" style="overflow:auto;padding:10px;">
				<%
                        		for (UploadFile uploadFile : uploadFileList) {
                        			if(uploadFile.getPlant().equals("一厂")){
                 %>
				<div class="easyui-draggable" data-options="handle:'#title'" style="width:220px;height:150px;float:left;margin :10px 20px 30px 50px;">
					<a href="#"  onclick="toSecond('<%=uploadFile.getCartype() %>')">
					<img style="width:220px;height:150px"  src="http://<%=request.getServerName()%>:8888/<%=uploadFile.getLocalname()%>"></a>
					<div id="title1" style="padding:5px;background:#ccc;color:#fff;text-align:center"><%=uploadFile.getOname() %></div>
				</div>
				<%
                        			}
                        		}
                 %>
				<div class="easyui-draggable" data-options="handle:'#title'" style="width:220px;height:150px;float:left;margin :10px 20px 30px 50px;">
					<a href="#" onclick="addImg()"><img src="<%=request.getContextPath()%>/assets/img/jia.png"></a>
					<div id="title1" style="padding:5px;background:#ccc;color:#fff;text-align:center">点击添加</div>
				</div>
				</div>
				<div title="二工厂" class="easyui-panel" data-options="" style="padding:10px;height:435px">
					<%
                        		for (UploadFile uploadFile : uploadFileList) {
                        			if(uploadFile.getPlant().equals("二厂")){
                 %>
				<div class="easyui-draggable" data-options="handle:'#title'" style="width:220px;height:150px;float:left;margin :10px 20px 30px 50px;">
					<a href="#"  onclick="toSecond('<%=uploadFile.getCartype() %>')">
					<img style="width:220px;height:150px"  src="http://<%=request.getServerName()%>:8888/<%=uploadFile.getLocalname()%>"></a>
					<div id="title1" style="padding:5px;background:#ccc;color:#fff;text-align:center"><%=uploadFile.getOname() %></div>
				</div>
				<%
                        			}
                        		}
                 %>
				<div class="easyui-draggable" data-options="handle:'#title'" style="width:220px;height:150px;float:left;margin :10px 20px 30px 50px;">
					<a href="#" onclick="addImg()" ><img src="<%=request.getContextPath()%>/assets/img/jia.png"></a>
					<div id="title1" style="padding:5px;background:#ccc;color:#fff;text-align:center">点击添加</div>
				</div>
				</div>
			</div>
		<div id="second" style="width:98%;padding:10px;overflow:auto;padding:10px;display:none; ">
		<div id="reportimg"></div>
		
		
		<div class="easyui-draggable" data-options="handle:'#title'" style="width:220px;height:150px;float:left;margin :10px 20px 30px 50px;">
			<a href="#" onclick="addImg()"><img src="<%=request.getContextPath()%>/assets/img/jia.png"></a>
			<div id="title1" style="padding:5px;background:#ccc;color:#fff;text-align:center">点击添加</div>
		</div>
		
		</div>
			
			<table id="dataGrid" style="width:98%;"></table>
					
			</div>
			<div  id='info' data-options="region:'east',split:true,collapsed:false,border:false,title :'关键信息',collapsed:true" style="width:300px;height:450px;padding:0px;hidden : true">

					<div id="p33" class="easyui-panel"   title="最新报告 <a href='#'  style='float:right;' onclick='initReportGrid(null,null)'>更多>> </a>"
						style=" height: 350px;  padding: 10px;"	data-options="iconCls:'icon-save'">
						<table border="0" cellspacing="1"	style="text-align: left; width: 100%">
							<!-- <tr>
								<td>名称</td>
								<td>时间</td>
							</tr> -->
							<%
								int newReportNo=0;
                        		for (Report report : newReports) {
                    		%>
   								<tr > 
	   								<td><a href="#" style="text-decoration: NONE;"
	   								       onclick="openPDF ('<%=report.getLocal_name() %>')">
	   								        <%=report.getOname().replace(".pdf", "")%>
	   								    </a>
	   								</td>	  
	   								<td><span id="newReportNo<%=newReportNo%>>"><%=report.getFile_create_time()%></span>
	   								</td>	
	   								<td colspan="2" style="height: 50%">
	   								<hr style="border: 1px dashed #ccc; width: 100%; height: 0px;"></hr>
		   							</td>
   								</tr>
   								<tr > 
		                     	<td colspan="2">
	   								<hr style="border: 1px dashed #ccc; width: 100%; height: 0px;"></hr>
		   							</td>
   								</tr>
		                    <%	 }	 %>
						</table>
					</div>
<%-- 					<div id="p1" class="easyui-panel" title="常用报告 <a id='imp' style='float:right;' href='#' onclick='toSetImpReport()'>设置>> </a>"
						style=" height: 210px; padding: 10px; "
						data-options="iconCls:'icon-save' ">
						<table border="0" cellspacing="1" style="text-align: left; width: 100%">
							<tr>
								<td>名称</td>
								<td>零件号</td>
							</tr>
							<%
                        		for (Impreport impreport : impreportList) {
                    		%>
   								<tr> 
	   								<td><a href="#" 
	   								       onclick="openPDF ('<%=impreport.getOdesc() %>')">
	   								        <%=impreport.getOname()%>
	   								    </a>
	   								</td>	  
	   								<td><%=impreport.getPartname().replace(".pdf", "")%>
	   								</td>	
   								</tr>
		                    <%	 }	 %>
						</table>
					</div> --%>
					<div id="p1" class="easyui-panel" title="报告更新日志
					 <a style='float:right;' href='#' id='replog' onclick='toMoreLog()'>更多>></a>"
						style="height: 330px; padding: 10px; "
						data-options="iconCls:'icon-save'">
						<table border="0" cellspacing="1"	style="text-align: left; width: 100%">
							<tr>
								<td>日期</td>
								<td>报告总数量</td>
							</tr>
							<tr>
								<td colspan="2" >
   								<hr style="border: 1px dashed #ccc; width: 100%; height: 0px;"></hr>
	   							</td>
							</tr>
							<%
                        		for (Reportlog reportlog : reportlogList) {
                    		%>
   								<tr > 
	   								<td><%=reportlog.getLast_modify_time()%>
	   								</td>	 
	   								<td><%=reportlog.getReportnum()%>
	   								</td>	
   								</tr>
   								<tr >
   								<td colspan="2">
   								<hr style="border: 1px dashed #ccc; width: 100%; height: 0px;"></hr>
	   							</td>
   								</tr>
		                    <%	 }	 %>
						</table>
					</div>
				</div>
			

		<div data-options="region:'south',border:false"
			style="height: 25px; background: #fff; padding: 5px;">
			<%@include file="/jsp/include/footer.jsp"%>
		</div>
	</div>
	</div>
	
</body>
<script type="text/javascript">
var roleNames = '<%=roleNames%>';
$(function(){
 
	$('#partTreeSearch').val("");
	
	if(roleNames.indexOf('Analysis') >= 0 ){
	}else{
		//隐藏第2个按钮
		$('div.datagrid-toolbar a').eq(1).hide();
		//隐藏第一条分隔线
		$('div.datagrid-toolbar div').eq(0).hide();
	}
	if(roleNames.indexOf("Admin") > 0 ){
	}else{
		$('#replog').html("");
		$('#imp').html("");
		
	}
	
	//initReportGrid("0",null);
});


	//初始化树
	function initPartTree(typeOid){
		//alert(typeOid);
		$('#partTree').tree(
				{
					url : getRootPath()+ "/ReportController/getSonReportTree.do",//getAllNasReport
					//url : "treeDemo.json",
					queryParams: {
						oid: typeOid
					},
					parentField : "pid",
					textFiled : "oname",
					idFiled : "id",
					onClick : function(node) {
						initReportGridById(node) ;
					}
		});
	}
	


	//初始化树
	$('#jiajuTree').tree(
			{
				url : getRootPath() + "/template/DPV/jiaju.json",
				//url : "treeDemo.json",
				parentField : "pid",
				textFiled : "name",
				idFiled : "id",
				onClick : function(node) {
					initReportGridById(node) ;
				}
	});
	
	$('#partTreeSearch').textbox({
	    buttonText:'搜索',    
	    iconCls:'icon-search', 
	    iconAlign:'left'  ,
	    prompt: '搜索框',
	    onClickButton: function(){
	    	var value=$('#partTreeSearch').val();
			$("#partTree").tree("search", value);    
		}
	});
	
	function toSetImpReport(){
		changeMenu('41','/ReportController/impReport.do','42');
	}
	function toSecond(carname) {
		$.ajax({
			type : 'post',
			async : false,
			url : getRootPath() + '/ReportController/getCarPic.do?cartype='+carname,
			success : function(result) {
				if(result!=null){
					var imgroot = '<%=request.getServerName()%>';
					$.each(result, function(key, item) {
						var imgurl ='http://'+imgroot+':8888/'+item.localname;
						var reportimg = 
						'<div class="easyui-draggable"  style="width:220px;height:150px;float:left;margin :10px 20px 30px 50px;">'+
						'<a href="#" onclick="toGride()"><img style="width:220px;height:150px" src="'+imgurl+'"></a>'+
						'<div  style="padding:5px;background:#ccc;color:#fff;text-align:center">'+item.oname+'</div>'+
						'</div>';
						$("#reportimg").append(reportimg);
					});
				}
			},
			dataType : 'json'
		});
		$("#first").css("display", "none"); 
		$("#second").css("display", ""); 
	}
	function toGride() {
		$("#first").css("display", "none"); 
		$("#second").css("display", "none"); 
		initReportGrid("0",null);
	}
	
	function addImg() {
		changeMenu('71','/ReportController/uploadImg.do','72');
	}
	
	function toMoreLog() {
		changeMenu('81','/ReportController/reportLogs.do','82');
	}
	
	function initReportGridById(node) {
		initReportGrid(node.id,null);
	}
	
	
	function initReportGrid(id,file_create_time) {
		//$("#info").layout("expand", 'east'); 
		$("#first").css("display", "none"); 
		$("#second").css("display", "none"); 
		// 初始化表格
	//	alert(id);
		var dataGrid =null;
		 dataGrid = $('#dataGrid').datagrid({
			sortName: 'file_create_time',
			rownumbers : true,	//如果为true，则显示一个行号列
			fitColumns : true,	//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动
			collapsible : true,	//定义是否显示可折叠按钮
			title : '报告详细信息',	//在面板头部显示的标题文本
			pagination : true,	//如果为true，则在DataGrid控件底部显示分页工具栏
			pagePosition : 'bottom',	//定义分页工具栏的位置
			method : 'post', //该方法类型请求远程数据
			singleSelect : false,//只能选一行
			checkOnSelect: true,
			url : getRootPath() + '/ReportController/getReportForGrid.do',
			queryParams: {
				pid: id,
				file_create_time: file_create_time
			},
			singleSelect : false,//只能选一行
			striped : true, //数据条纹显示
			frozenColumns : [ [ {//不可被删除的列
				field : 'ck',	//列字段名称		
				checkbox : true	//如果为true，则显示复选框
			} ] ],
			columns : [ [  {
				field : 'memo',
				title : '图片',
				width : 100,
				sortable : true,
				 formatter:function(value,row){
				      var str = "";
				      if(value!="" &&value!=null&&value!='null'){
				    	
				      str = "<img style='height: 80px;width: 80px;text-align: center;' src='http://<%=request.getServerName()%>:8888/htmlimg/"+value+"'/>";
				      return str;
				      }
				      return "无图片";
		    	} 
			},
			 {
				field : 'id',
				title : 'id',
				width : 100,
				hidden : true,
				sortable : true	//如果为true，则允许列使用排序
			}, {
				field : 'oname',
				title : '文档名称',
				width : 200,
				sortable : true	//如果为true，则允许列使用排序
			}, {
				field : 'odesc',
				title : '文件类型',
				width : 100,
				formatter: function(value,row,index){ return "基础报告";}

			},{
				field : 'file_create_time',
				title : '生成时间',
				width : 100
			}] ],
		//	onClickRow: function(rowIndex, rowData){
		//		$('#dataGrid').datagrid('checkRow', rowIndex);        
		//	},
			onDblClickRow: function(rowIndex, rowData){
				$('#dataGrid').datagrid('checkRow', rowIndex); 
				openPDF(rowData.local_name);
			},
			 toolbar : [{
				 text : '打开报告',
				iconCls : 'icon-edit',
				handler : function(){
					var rows = $('#dataGrid').datagrid('getSelections');
					if (rows.length == 0) {
						$.messager.alert('提示','请选择操作项','info');
						return;
					} else if (rows.length > 1) {
						$.messager.alert('提示','只能选择一项','info');
						return;
					}
					filePath = rows[0].local_name;
					openPDF(filePath);
				} 
			}/* ,{
				 text : '',//下载
					//iconCls : 'icon-edit',
					handler : function(){
						var rows = $('#dataGrid').datagrid('getSelections');
						if (rows.length == 0) {
							$.messager.alert('提示','请选择操作项','info');
							return;
						} else if (rows.length > 1) {
							$.messager.alert('提示','只能选择一项','info');
							return;
						}
						filePath = rows[0].local_name;
						window.open(getPDFUrl(filePath));
					} 
				} */
				,{
				 text : '下载分析模板',
					iconCls : 'icon-edit',
					handler : function(){
						var rows = $('#dataGrid').datagrid('getSelections');
						if (rows.length == 0) {
							$.messager.alert('提示','请选择操作项','info');
							return;
						} else if (rows.length > 1) {
							$.messager.alert('提示','只能选择一项','info');
							return;
						}
						var rootPath=getRootPath().replace("8080","8888").replace("easy","nus").replace("devfw","nus");
						<%-- filePath = rows[0].local_name;
						var rootPath=getRootPath().replace("8080","8888").replace("easy","nus").replace("devfw","nus");
						var filepath= rows[0].nas_path;
						var filepath=filepath.replace("<%=Parameter.NAS_ROOT%>\\","").replace("HTMLFolder\\","").replace("OnDemand\\","");
						window.open(rootPath+"/Technical_Portfolio.vsd"); --%>
						if (rows) {
							$.ajax({
								type : 'post',
								async : false,
								url : getRootPath() + '/ReportController/getvsd.do?pdfpath='+rows[0].nas_path,
								success : function(result) {
									if(result.error!=null){
										alert(result.error);
									}else{
										window.open(rootPath+result.path.replace(/\\/g,"/")	); 
									}
								},
								dataType : 'json'
							});
						}
					} 
				}
			 ], 
			 
			 
			remoteFilter : true,	//设置为true时，启用远程过滤
			filterDelay : 700,		//延迟过滤 'text' 过滤器组件中最后一次键盘输入事件
			filterStringify : function(data) {	//字符串化过滤器规则的函数
				return JSON.stringify(data);
			}
		});
		 dataGrid.datagrid('enableFilter');
		 if(roleNames.indexOf('Analysis') > 0 ){
			}else{
				//隐藏第2个按钮
				$('div.datagrid-toolbar a').eq(1).hide();
				//隐藏第一条分隔线
				$('div.datagrid-toolbar div').eq(0).hide();
			}
	
	}
	
	function openPDF(filePath){
		var url= getRootPath()+"/ReportController/pdf.do?url="+getPDFUrl(filePath)
		window.open(url);
}
	function getPDFUrl(filePath){
		var rootPath=getRootPath().replace("8080","8888").replace("easy","pdf").replace("devfw","pdf");
		
		var pathHead='<%=DateUtil.getPath()%>';
		if (pathHead==null){
			window.location.href=getRootPath();
		}
		if (filePath==null||filePath==""){
			alert("filePath is NaN");
		}
		filePath=filePath.replace(/\\/g,"/");
		return rootPath+"/"+filePath;
}
	</script>


<script>

$('#gongchang').combobox({  
    //url:'combobox_data.json',    
    	valueField: 'id',
		textField: 'oname',
		url: getRootPath()+"/ReportController/findReport.do?pid=0",
		onSelect: function(record){
			changeChexing(record.id);
		},
		onLoadSuccess: function () { //加载完成后,设置选中第一项
            var val = $(this).combobox("getData");
            for (var item in val[0]) {
                if (item == "id") {
                    $(this).combobox("select", val[0][item]);
                    changeChexing(val[0][item]);
                }
            }
        }
}); 




//$('#gongchang').combobox('select', '1');


function changeJiaju(){
			$('#chexing').combobox('loadData', [{
				label: 'A级车',
				value: 'A级车'
			},{
				label: 'B级车',
				value: 'B级车'
			}]
			);
			
}
function changeChexing(fatherId){
	$('#chexing').combobox({  
	    //url:'combobox_data.json',    
	    	valueField: 'id',
			textField: 'oname',
			url: getRootPath()+"/ReportController/findReport.do?pid="+fatherId,
			onSelect: function(rec){
				initPartTree(rec.id);
			},
			onLoadSuccess: function () { //加载完成后,设置选中第一项
	            var val = $(this).combobox("getData");
				var def = "";
	            for (var item in val[val.length-1]) {
	                if (item == "id") {
	                	def = val[val.length-1][item];
	                }
	            }
	            $(this).combobox("select", def);
                initPartTree(val[val.length-1][item]); 
	        }
	});
}

  

		function   ExeRun(command)  {
			  window.oldOnError=window.onerror;     
			  window._command=command;     
			  window.onerror=function(err)     
			  {     
			  if(err.indexOf('automation')!=-1)     
			  {     
			  //alert("命令"+window._command+"已经被用户禁止!");       
			            return   true;     
			  }     
			  else   return   false;     
			  }     
			  var   wsh=new   ActiveXObject("WScript.Shell");     
			  if(wsh)     
			  wsh.Run(command);     
			  window.onerror=window.oldOnError; 
	  } 
	//$('#report').tabs('select',"报告信息");  
	</script>


		  
	



</html>
